package com.atguigu.gmall.product.controller;

import com.atguigu.gmall.common.result.Result;
import com.atguigu.gmall.model.product.SkuInfo;
import com.atguigu.gmall.model.product.SkuSaleAttrValue;
import com.atguigu.gmall.model.product.SpuImage;
import com.atguigu.gmall.model.product.SpuSaleAttr;
import com.atguigu.gmall.product.mapper.SkuInfoMapper;
import com.atguigu.gmall.product.service.ManageService;
import com.baomidou.mybatisplus.core.metadata.IPage;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @Description: TODO
 * @Author: Mr.Cao
 * @DateTime: 2021/10/9 18:59
 * BMW F750GS
 **/
@RestController
@RequestMapping("/admin/product")
@Api(tags = "商品SKU接口")
public class SkuManageController {
    @Autowired
    private ManageService manageService;

   /**
    * 分页获取sku列表
    * */
    @GetMapping("list/{page}/{limit}")
    public Result getSkuPage(@PathVariable long page,@PathVariable long limit){

        IPage skuPage = manageService.getSkuPage(page, limit);
        return Result.ok(skuPage);
    }
    /**
     *根据spuId获取图片列表
     * */
    @GetMapping("spuImageList/{spuId}")
    public Result spuImageList(@PathVariable long spuId){

      List<SpuImage> list =  manageService.spuImageList(spuId);
        return Result.ok(list);
    }
    /**
     *根据spuId获取销售属性
     * */
    @GetMapping("spuSaleAttrList/{spuId}")
    public Result spuSaleAttrList(@PathVariable long spuId){
          List<SpuSaleAttr> list =  manageService.spuSaleAttrList(spuId);
        return Result.ok(list);
    }


    /**
     * sku商品上架
     * */
    @GetMapping("onSale/{skuId}")
    public Result onSale(@PathVariable Long skuId){
        manageService.onSale(skuId);
        return Result.ok();
    }
    /**
     * sku商品下架
     * */
    @GetMapping("cancelSale/{skuId}")
    public Result cancelSale(@PathVariable Long skuId){
        manageService.cancelSale(skuId);
        return Result.ok();
    }
    /**
     * 保存sku商品
     * */
    @PostMapping("saveSkuInfo")
    public Result saveSkuInfo(@RequestBody SkuInfo skuInfo){
        manageService.saveSkuInfo(skuInfo);
        return Result.ok();
    }
}
